unit VHTTP;

interface

uses
  Winapi.Windows, system.Classes, system.SyncObjs, system.Types,
  system.SysUtils;

type

  TVHTTPDLL = Class
  private
    Mydll: HMODULE;
    FError: string;
    Finit: Boolean;
    procedure SetError(const Value: string);
  protected
    procedure init;
  public

    constructor Create;
    destructor Destroy; override;
    property Error: string read FError write SetError;
    function CSHChar(s: PAnsiChar): PAnsiChar;
    function CSH1Char(s: PAnsiChar): PAnsiChar;
    function CHttpurl(stype: Integer; url, header, buf: PAnsiChar): PAnsiChar;
  End;

const
  Vhttpdllname = 'Vhttp.dll';

implementation

{ TVHTTPDLL }
var
  SHChar: function(s: PAnsiChar): PAnsiChar; cdecl;
  SH1Char: function(s: PAnsiChar): PAnsiChar; cdecl;
  Httpurl: function(stype: Integer; url, header, buf: PAnsiChar)
    : PAnsiChar; cdecl;

function TVHTTPDLL.CHttpurl(stype: Integer; url, header, buf: PAnsiChar)
  : PAnsiChar;
begin
  Result := Httpurl(stype, url, header, buf)
end;

constructor TVHTTPDLL.Create;
begin
  Self.init;
end;

function TVHTTPDLL.CSH1Char(s: PAnsiChar): PAnsiChar;
begin
  Result := SH1Char(s);
end;

function TVHTTPDLL.CSHChar(s: PAnsiChar): PAnsiChar;
begin
  Result := SHChar(s);
end;

destructor TVHTTPDLL.Destroy;
begin
  if Finit then
  begin
    freeLibrary(Mydll);
  end;

end;

procedure TVHTTPDLL.init;
begin
  FError := '';
  Mydll := LoadLibrary(Vhttpdllname);
  if Mydll <> 0 then
  begin
    @SHChar := GetProcAddress(Mydll, 'SHChar');
    @SH1Char := GetProcAddress(Mydll, 'SH1Char');
    @Httpurl := GetProcAddress(Mydll, 'Httpurl');
    if not Assigned(SHChar) and not Assigned(SH1Char) and not Assigned(Httpurl)
    then
    begin
      raise Exception.Create('init Vhttp error');
      Exit;
    end;

    Finit := True;

    Exit;
  end;
  FError := 'loadlibrayf error';
  Exit;
end;

procedure TVHTTPDLL.SetError(const Value: string);
begin
  FError := Value;
end;

end.
